/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, Hardware
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <fcntl.h>
#include <fstream>
#include <ctime>

#include "gtest/gtest.h"
#include "hmfs_test_utils.h"

using namespace testing;
using namespace testing::ext;

namespace OHOS {
namespace Hmfs {
const std::string F2FS_RESIZE_BINARY_PATH = "/system/bin/resize.f2fs";
const std::string  HMFS_RESIZE_BINARY_PATH = "/system/bin/resize.hmfs";
const std::string F2FS_MKFS_BINARY_PATH = "/system/bin/mkfs.f2fs";
const std::string  HMFS_MKFS_BINARY_PATH = "/system/bin/mkfs.hmfs";
const std::string FSCK_BINARY_PATH = "/system/bin/fsck.f2fs";

class ResizeHmfsSingleTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp() override;
    void TearDown() override;
    static int32_t ExecResizeBinary(std::string tool, std::vector<std::string> &params, std::string device);
    static int32_t ExecutableCmd(const char *path, char *const argv[]);
    static int32_t ExecutableDdCmd(std::string& device, const int32_t count);
    static int32_t ExecutableRmCmd(std::string file);
    static int32_t ExecutableMkfsCmd(std::string tool, std::string& device);
    static int32_t ExecutableCmdWithOutput(std::vector<std::string>& params, std::string& outputFile);
    static int32_t ExecResizeBinaryWithOutput(std::string tool, std::vector<std::string>& params, 
        std::string device, std::string& outputFile);
    static int32_t ExecFsckWithOutput(std::string& device, std::string& outputFile);
};

void ResizeHmfsSingleTest::SetUpTestCase() {}

void ResizeHmfsSingleTest::TearDownTestCase() {}

void ResizeHmfsSingleTest::SetUp() {}

void ResizeHmfsSingleTest::TearDown()
{
    std::vector<char*> argv;
    argv.push_back(const_cast<char*>("/bin/sh"));
    argv.push_back(const_cast<char*>("-c"));
    argv.push_back(const_cast<char*>("rm -rf /data/Fs* /data/HM*")); 
    argv.push_back(nullptr);
    
    ResizeHmfsSingleTest::ExecutableCmd(argv[0], argv.data());
}

int32_t ResizeHmfsSingleTest::ExecutableRmCmd(std::string file)
{
    std::vector<char*> argv;
    argv.push_back(const_cast<char*>("/bin/sh"));
    argv.push_back(const_cast<char*>("-c"));
    argv.push_back(const_cast<char*>(("rm -rf " + file).c_str())); 
    argv.push_back(nullptr);
    
    return ResizeHmfsSingleTest::ExecutableCmd(argv[0], argv.data());
}


int32_t ResizeHmfsSingleTest::ExecutableCmd(const char *path, char *const argv[])
{
    if (path == nullptr || argv == nullptr ) {
        return -1;
    }

    pid_t pid = fork();
    if (pid < 0) {
        return -errno;
    }

    if (pid == 0) {
        execv(path, argv);
        _exit(EXIT_FAILURE);
    }

    int status = -1;
    pid_t wpid = waitpid(pid, &status, 0);
    if (wpid == -1 || wpid != pid) {
        return -errno;
    }

    if (WIFEXITED(status)) {
        return WEXITSTATUS(status);
    }
    return -ECHILD;
}

int32_t ResizeHmfsSingleTest::ExecutableCmdWithOutput(std::vector<std::string>& params, std::string& outputFile)
{
    pid_t pid = fork();
    if (pid < 0) {
        return -errno;
    }

    if (pid == 0) {
        int fd = open(outputFile.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
        if (fd < 0) {
            _exit(EXIT_FAILURE);
        }
        dup2(fd, STDOUT_FILENO);
        close(fd);

        std::vector<char*> argv;
        for (const auto& param : params) {
            argv.push_back(const_cast<char*>(param.c_str()));
        }
        argv.push_back(nullptr);
        execv(argv[0], argv.data());
        _exit(EXIT_FAILURE);
    }

    int status = -1;
    pid_t wpid = waitpid(pid, &status, 0);
    if (wpid == -1 || wpid != pid) {
        return -errno;
    }

    if (WIFEXITED(status)) {
        return WEXITSTATUS(status);
    }
    return -ECHILD;
}


int32_t ResizeHmfsSingleTest::ExecutableMkfsCmd(std::string tool, std::string& device)
{
    std::vector<char*> argv;
    if (tool == "f2fs") {
        argv.emplace_back(const_cast<char*>(F2FS_MKFS_BINARY_PATH.c_str()));
    }
    if (tool == "hmfs") {
        argv.emplace_back(const_cast<char*>(HMFS_MKFS_BINARY_PATH.c_str()));
    }
    argv.push_back(const_cast<char*>((device).c_str()));
    argv.push_back(nullptr);
    return ResizeHmfsSingleTest::ExecutableCmd(argv[0], argv.data());
}

int32_t ResizeHmfsSingleTest::ExecutableDdCmd(std::string& device, int32_t count)
{
    std::string countStr = std::to_string(count);
    std::vector<char*> argv;
    argv.push_back(const_cast<char*>("/system/bin/dd"));
    argv.push_back(const_cast<char*>("if=/dev/zero"));
    argv.push_back(const_cast<char*>(("of=" + device).c_str()));
    argv.push_back(const_cast<char*>("bs=1M"));
    argv.push_back(const_cast<char*>(("count=" + countStr).c_str()));
    argv.push_back(nullptr);
    return ResizeHmfsSingleTest::ExecutableCmd(argv[0], argv.data());
}

int32_t ResizeHmfsSingleTest::ExecResizeBinary(std::string tool, std::vector<std::string> &params, std::string device)
{
    std::vector<char*> argv;
    if (tool == "f2fs") {
        argv.emplace_back(const_cast<char*>(F2FS_RESIZE_BINARY_PATH.c_str()));
    }
    if (tool == "hmfs") {
        argv.emplace_back(const_cast<char*>(HMFS_RESIZE_BINARY_PATH.c_str()));
    }
    for (const auto &param : params) {
        argv.push_back(const_cast<char*>(param.c_str()));
    }
    argv.push_back(const_cast<char*>(device.c_str()));
    argv.push_back(nullptr);
    return ResizeHmfsSingleTest::ExecutableCmd(argv[0], argv.data());
}

int32_t ResizeHmfsSingleTest::ExecResizeBinaryWithOutput(std::string tool, std::vector<std::string>& params,
    std::string device, std::string& outputFile)
{
    std::vector<std::string> argv;
    if (tool == "f2fs") {
        argv.emplace_back(const_cast<char*>(F2FS_RESIZE_BINARY_PATH.c_str()));
    }
    if (tool == "hmfs") {
        argv.emplace_back(const_cast<char*>(HMFS_RESIZE_BINARY_PATH.c_str()));
    }
    for (const auto& param : params) {
        argv.push_back(param);
    }
    argv.push_back(device);
    return ExecutableCmdWithOutput(argv, outputFile);
}

int32_t ResizeHmfsSingleTest::ExecFsckWithOutput(std::string& device, std::string& outputFile)
{
    std::vector<std::string> argv;
    argv.push_back(FSCK_BINARY_PATH);
    argv.push_back(device);
    return ExecutableCmdWithOutput(argv, outputFile);
}

/*
 * @tc.name: ResizeHmfsSingleTest_V_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_V_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_V_001 BEGIN" << std::endl;
    std::vector<std::string> params;
    params.push_back("/system/bin/resize.hmfs");
    params.push_back("-V");

    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableCmdWithOutput(params, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Hmfstool version") != std::string::npos);
    std::cout << "ResizeHmfsSingleTest_V_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_C_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_C_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_C_001 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));
    std::vector<std::string> params;
    params.clear();
    params.push_back("-C");
    params.push_back("utf8");
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
   
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);

    ASSERT_EQ(f2fsSuperBlock->encoding, hmfsSuperBlock->encoding);
    ASSERT_EQ(f2fsSuperBlock->encodingFlags, hmfsSuperBlock->encodingFlags);
    ASSERT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);

    ASSERT_EQ(f2fsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_CASEFOLD);
    ASSERT_EQ(hmfsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_CASEFOLD);
    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_C_001.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_C_001.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_C_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_C_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_C_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_C_002 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));
    std::vector<std::string> params;
    params.clear();
    params.push_back("-C");
    params.push_back("ascii");

    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, device));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    std::cout << "ResizeHmfsSingleTest_C_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_O_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_O_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_O_001 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));
    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("extra_attr,project_quota");
    
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);

    std::string hmDevice = "/data/HMFsCTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    
    ASSERT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_EXTRA_ATTR);
    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_PRJQUOTA);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_EXTRA_ATTR);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_PRJQUOTA);
    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_O_001.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_O_001.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_O_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_O_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_O_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_O_002 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));
    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("casefold");
    params.push_back("-C");
    params.push_back("utf8");
    
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    
    ASSERT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
    ASSERT_EQ(f2fsSuperBlock->encoding, hmfsSuperBlock->encoding);
    ASSERT_EQ(f2fsSuperBlock->encodingFlags, hmfsSuperBlock->encodingFlags);

    ASSERT_EQ(f2fsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_CASEFOLD);
    ASSERT_EQ(hmfsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_CASEFOLD);
    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_O_001.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_O_001.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_O_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_O_003
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_O_003, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_O_003 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));
    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("casefold,extra_attr,project_quota");
    params.push_back("-C");
    params.push_back("utf8");
    
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);

    ASSERT_EQ(f2fsSuperBlock->features, hmfsSuperBlock->features);
    ASSERT_EQ(f2fsSuperBlock->encoding, hmfsSuperBlock->encoding);
    ASSERT_EQ(f2fsSuperBlock->encodingFlags, hmfsSuperBlock->encodingFlags);

    ASSERT_EQ(f2fsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_CASEFOLD);
    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_EXTRA_ATTR);
    ASSERT_TRUE(f2fsSuperBlock->features & HMFS_FEATURE_PRJQUOTA);

    ASSERT_EQ(hmfsSuperBlock->encoding, HMFS_ENC_UTF8_12_1);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_CASEFOLD);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_EXTRA_ATTR);
    ASSERT_TRUE(hmfsSuperBlock->features & HMFS_FEATURE_PRJQUOTA);
    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_O_001.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_O_001.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_O_003 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_O_004
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_O_004, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_O_004 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));
    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("abcd");
    
    std::string outputFile = "/data/test_output_ResizeHmfsSingleTest_O_004.txt";
    ASSERT_EQ(1, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("hmfs", params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Error: Wrong features") != std::string::npos);
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableRmCmd(outputFile));
    std::cout << "ResizeHmfsSingleTest_O_004 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_s_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_s_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_s_001 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));
    std::vector<std::string> params;
    params.clear();
    params.push_back("-t");
    params.push_back("102400");

    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("hmfs", params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Nothing to resize, now only supports resizing with safe resize flag") != std::string::npos);

    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableRmCmd(outputFile));
    std::cout << "ResizeHmfsSingleTest_s_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_t_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_t_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_t_001 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    
    //mkfs fsck check
    std::string F2fsMkfsFsckOutFileName = "/data/Fsck_F2fs_Mkfs_SingleParams_t_001.txt";
    int32_t fsckMkfsF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsMkfsFsckOutFileName);
    std::string HmfsMkfsFsckOutFileName = "/data/Fsck_Hmfs_Mkfs_SingleParams_t_001.txt";
    int32_t fsckMkfsHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsMkfsFsckOutFileName);
    ASSERT_EQ(fsckMkfsF2fsRes, fsckMkfsHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsMkfsFsckOutFileName, hmDevice));
    if (fsckMkfsHmfsRes == 0) {
        ASSERT_EQ(0, ExecutableRmCmd(HmfsMkfsFsckOutFileName));
        ASSERT_EQ(0, ExecutableRmCmd(F2fsMkfsFsckOutFileName));
    }

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->blockCount, hmfsSuperBlock->blockCount);

    uint64_t targetSectors = 102400;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back(std::to_string(targetSectors));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);    
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto resizeF2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, resizeF2fsSuperBlock);
    auto resizeHmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, resizeHmfsSuperBlock);
    ASSERT_EQ(resizeF2fsSuperBlock->blockCount, resizeHmfsSuperBlock->blockCount);
    ASSERT_EQ(hmfsSuperBlock->blockCount, resizeHmfsSuperBlock->blockCount*2);

    //值校验
    uint64_t targetBlockCounts = targetSectors >> resizeF2fsSuperBlock->logSectorsPerBlk;
    ASSERT_EQ(targetBlockCounts, resizeF2fsSuperBlock->blockCount);

    //resize fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_t_001.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_t_001.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckHmfsRes == 0) {
        ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
        ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
    }
    std::cout << "ResizeHmfsSingleTest_t_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_t_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_t_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_t_002 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));
    uint64_t targetSectors = 122880;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back(std::to_string(targetSectors));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);

    ASSERT_EQ(f2fsSuperBlock->blockCount, hmfsSuperBlock->blockCount);
    //值校验
    uint64_t targetBlockCounts = targetSectors >> f2fsSuperBlock->logSectorsPerBlk;
    ASSERT_EQ(targetBlockCounts, f2fsSuperBlock->blockCount);

    targetSectors = 184320;
    std::vector<std::string> resizeParams;
    resizeParams.clear();
    resizeParams.push_back("-t");
    resizeParams.push_back(std::to_string(targetSectors));

    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", resizeParams, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    auto resizeF2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, resizeF2fsSuperBlock);

    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", resizeParams, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto resizeHmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, resizeHmfsSuperBlock);

    ASSERT_EQ(resizeF2fsSuperBlock->blockCount, resizeHmfsSuperBlock->blockCount);
    //值校验
    targetBlockCounts = targetSectors >> resizeF2fsSuperBlock->logSectorsPerBlk;
    ASSERT_EQ(targetBlockCounts, resizeF2fsSuperBlock->blockCount);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_t_002.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_t_002.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_t_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_t_003
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_t_003, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_t_003 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);

    std::string hmDevice = "/data/HMFsCTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->blockCount, hmfsSuperBlock->blockCount);

    std::vector<std::string> resizeParams;
    resizeParams.clear();

    EXPECT_NE(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", resizeParams, device));
    EXPECT_NE(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", resizeParams, hmDevice));
    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_t_002.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_t_002.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_t_003 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_t_004
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_t_004, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_t_004 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 1000));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 1000));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    ASSERT_EQ(f2fsSuperBlock->blockCount, hmfsSuperBlock->blockCount);
    uint64_t targetSectors = 1024000;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back(std::to_string(targetSectors));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    auto resizeF2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, resizeF2fsSuperBlock);
    
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto resizeHmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, resizeHmfsSuperBlock);
    ASSERT_EQ(resizeF2fsSuperBlock->blockCount, resizeHmfsSuperBlock->blockCount);
    ASSERT_EQ(hmfsSuperBlock->blockCount, resizeHmfsSuperBlock->blockCount*2);
    //值校验
    uint64_t targetBlockCounts = targetSectors >> resizeF2fsSuperBlock->logSectorsPerBlk;
    ASSERT_EQ(targetBlockCounts, resizeF2fsSuperBlock->blockCount);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_t_001.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_t_001.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_t_004 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_t_005
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_t_005, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_t_005 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("20");
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("hmfs", params, device, outputFile));

    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Error: Device size is not sufficient for F2FS volume, more segment needed") != std::string::npos);

    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableRmCmd(outputFile));
    std::cout << "ResizeHmfsSingleTest_t_005 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_t_006
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_t_006, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_t_006 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-t");
    params.push_back("409600");
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("hmfs", params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Out-of-range Target") != std::string::npos);
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableRmCmd(outputFile));
    std::cout << "ResizeHmfsSingleTest_t_006 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_001 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));

    double overprovision = 60.0;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back(std::to_string(overprovision));
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("f2fs", params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Info: Overprovision ratio = 60.000%") != std::string::npos);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCkeckPoint);

    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCkeckPoint);
    std::cout << "overprovSegmentCount: " << f2fsCkeckPoint->overprovSegmentCount << std::endl;
    std::cout << "rsvdSegmentCount: " << f2fsCkeckPoint->rsvdSegmentCount << std::endl;

    uint32_t reservedSegments = (2 * (100 / overprovision + 1) + 6) * f2fsSuperBlock->segsPerSection;
    std::cout << "f2fsSuperBlock->segsPerSection: " << f2fsSuperBlock->segsPerSection << std::endl;
    std::cout << "校验-o参数 reservedSegments = " << reservedSegments << std::endl;
    uint32_t overprov_segment_count = (f2fsSuperBlock->segmentCountInMain - reservedSegments) * overprovision / 100;
    overprov_segment_count = overprov_segment_count + reservedSegments;
    std::cout << "校验-o参数 overprov_segment_count = " << overprov_segment_count << std::endl;
    ASSERT_EQ(f2fsCkeckPoint->overprovSegmentCount, hmfsCkeckPoint->overprovSegmentCount);
    ASSERT_EQ(f2fsCkeckPoint->rsvdSegmentCount, hmfsCkeckPoint->rsvdSegmentCount);
    ASSERT_EQ(f2fsCkeckPoint->overprovSegmentCount, overprov_segment_count);
    ASSERT_EQ(f2fsCkeckPoint->rsvdSegmentCount, reservedSegments);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_o_001.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_o_001.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_o_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_002 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 1000));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));

    double overprovision = 60.0;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("1024000");
    params.push_back("-o");
    params.push_back(std::to_string(overprovision));
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("f2fs", params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Info: Overprovision ratio = 60.000%") != std::string::npos);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCkeckPoint);

    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 1000));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCkeckPoint);
    std::cout << "overprovSegmentCount: " << f2fsCkeckPoint->overprovSegmentCount << std::endl;
    std::cout << "rsvdSegmentCount: " << f2fsCkeckPoint->rsvdSegmentCount << std::endl;

    uint32_t reservedSegments = (2 * (100 / overprovision + 1) + 6) * f2fsSuperBlock->segsPerSection;
    std::cout << "f2fsSuperBlock->segsPerSection: " << f2fsSuperBlock->segsPerSection << std::endl;
    std::cout << "校验-o参数 reservedSegments = " << reservedSegments << std::endl;
    uint32_t overprov_segment_count = (f2fsSuperBlock->segmentCountInMain - reservedSegments) * overprovision / 100;
    overprov_segment_count = overprov_segment_count + reservedSegments;
    std::cout << "校验-o参数 overprov_segment_count = " << overprov_segment_count << std::endl;
    ASSERT_EQ(f2fsCkeckPoint->overprovSegmentCount, hmfsCkeckPoint->overprovSegmentCount);
    ASSERT_EQ(f2fsCkeckPoint->rsvdSegmentCount, hmfsCkeckPoint->rsvdSegmentCount);
    ASSERT_EQ(f2fsCkeckPoint->overprovSegmentCount, overprov_segment_count);
    ASSERT_EQ(f2fsCkeckPoint->rsvdSegmentCount, reservedSegments);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_o_002.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_o_002.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_o_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_003
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_003, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_003 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back("1");
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("hmfs", params, device, outputFile));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Error: Device size is not sufficient for F2FS volume, more segment needed") != std::string::npos);
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableRmCmd(outputFile));
    std::cout << "ResizeHmfsSingleTest_o_003 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_004
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_004, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_004 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back("100");
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    std::cout << "ResizeHmfsSingleTest_o_004 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_005
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_005, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_005 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));

    double overprovision = 0.0;
    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back("0");

    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCkeckPoint);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCkeckPoint);
    overprovision = HmfsCommon::GetInstance().GetBestOverProvision(hmfsSuperBlock.get());
    ASSERT_EQ(f2fsCkeckPoint->overprovSegmentCount, hmfsCkeckPoint->overprovSegmentCount);
    ASSERT_EQ(f2fsCkeckPoint->rsvdSegmentCount, hmfsCkeckPoint->rsvdSegmentCount);
    uint32_t reservedSegments = (2 * (100 / overprovision + 1) + 6) * f2fsSuperBlock->segsPerSection;
    std::cout << "f2fsSuperBlock->segsPerSection: " << f2fsSuperBlock->segsPerSection << std::endl;
    std::cout << "校验-o参数 reservedSegments = " << reservedSegments << std::endl;
    uint32_t overprov_segment_count = (f2fsSuperBlock->segmentCountInMain - reservedSegments) * overprovision / 100;
    overprov_segment_count = overprov_segment_count + reservedSegments;
    std::cout << "校验-o参数 overprov_segment_count = " << overprov_segment_count << std::endl;
    ASSERT_EQ(f2fsCkeckPoint->overprovSegmentCount, hmfsCkeckPoint->overprovSegmentCount);
    ASSERT_EQ(f2fsCkeckPoint->rsvdSegmentCount, hmfsCkeckPoint->rsvdSegmentCount);
    ASSERT_EQ(f2fsCkeckPoint->overprovSegmentCount, overprov_segment_count);
    ASSERT_EQ(f2fsCkeckPoint->rsvdSegmentCount, reservedSegments);

    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_o_005.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_o_005.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_o_005 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_006
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_006, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_006 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back("1000");
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCkeckPoint);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCkeckPoint);

    ASSERT_EQ(f2fsCkeckPoint->overprovSegmentCount, hmfsCkeckPoint->overprovSegmentCount);
    ASSERT_EQ(f2fsCkeckPoint->rsvdSegmentCount, hmfsCkeckPoint->rsvdSegmentCount);
    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_o_006.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_o_006.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_o_006 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_o_007
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_o_007, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_o_007 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-o");
    params.push_back("-1000");
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCkeckPoint);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCkeckPoint);

    ASSERT_EQ(f2fsCkeckPoint->overprovSegmentCount, hmfsCkeckPoint->overprovSegmentCount);
    ASSERT_EQ(f2fsCkeckPoint->rsvdSegmentCount, hmfsCkeckPoint->rsvdSegmentCount);
    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_o_007.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_o_007.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_o_007 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_i_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_i_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_i_001 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-i");
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCkeckPoint);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCkeckPoint);

    ASSERT_EQ(f2fsCkeckPoint->cpFlags, hmfsCkeckPoint->cpFlags);
    ASSERT_EQ(f2fsCkeckPoint->checksumOffset, f2fsCkeckPoint->checksumOffset);
    ASSERT_TRUE(hmfsCkeckPoint->cpFlags & CP_FLAG_LARGE_NAT_BITMAP);
    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_o_004.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_o_004.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_i_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_i_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_i_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_i_002 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 1000));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("f2fs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("1024000");
    params.push_back("-i");
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("f2fs", params, device));
    std::cout << "----------------------------------------------------------------F2FS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(device, f2fsSuperBlock);
    auto f2fsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(device, f2fsCkeckPoint);

    std::string hmDevice = "/data/HMFsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(hmDevice, 1000));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", hmDevice));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, hmDevice));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(hmDevice);

    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetSuperBlock(hmDevice, hmfsSuperBlock);
    auto hmfsCkeckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(hmDevice, hmfsCkeckPoint);

    ASSERT_EQ(f2fsCkeckPoint->cpFlags, hmfsCkeckPoint->cpFlags);
    ASSERT_EQ(f2fsCkeckPoint->checksumOffset, f2fsCkeckPoint->checksumOffset);
    ASSERT_TRUE(hmfsCkeckPoint->cpFlags & CP_FLAG_LARGE_NAT_BITMAP);
    //fsck check
    std::string HmfsFsckOutFileName = "/data/Fsck_Hmfs_SingleParams_o_004.txt";
    std::string F2fsFsckOutFileName = "/data/Fsck_F2fs_SingleParams_o_004.txt";
    int32_t fsckF2fsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(device, F2fsFsckOutFileName);
    int32_t fsckHmfsRes = ResizeHmfsSingleTest::ExecFsckWithOutput(hmDevice, HmfsFsckOutFileName);
    ASSERT_EQ(fsckF2fsRes, fsckHmfsRes);
    ASSERT_TRUE(PrintFsckErrorMsg(HmfsFsckOutFileName, hmDevice));
    if (fsckF2fsRes == fsckHmfsRes && fsckHmfsRes == 0) {
        if (PrintFsckErrorMsg(F2fsFsckOutFileName, device)) {
            ASSERT_EQ(0, ExecutableRmCmd(HmfsFsckOutFileName));
            ASSERT_EQ(0, ExecutableRmCmd(F2fsFsckOutFileName));
        }
    }
    std::cout << "ResizeHmfsSingleTest_i_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_d_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_d_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_d_001 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-d");
    params.push_back("0");
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("hmfs", params, device, outputFile));
    std::string output = ReadFile(outputFile);
    // ASSERT_TRUE(output.find("Info: Debug level = 0") != std::string::npos);
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableRmCmd(outputFile));
    std::cout << "ResizeHmfsSingleTest_d_001 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_d_002
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_d_002, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_d_002 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-d");
    params.push_back("1");
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("hmfs", params, device, outputFile));
    std::string output = ReadFile(outputFile);

    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableRmCmd(outputFile));
    // ASSERT_TRUE(output.find("Info: Debug level = 1") != std::string::npos);
    std::cout << "ResizeHmfsSingleTest_d_002 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_d_003
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_d_003, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_d_003 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-d");
    params.push_back("10");
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("hmfs", params, device, outputFile));
    std::cout << "----------------------------------------------------------------HMFS" << std::endl;
    PrintSuperBlockAndCheckPointData(device);

    std::string output = ReadFile(outputFile);
    // ASSERT_TRUE(output.find("Info: Debug level = 10") != std::string::npos);
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableRmCmd(outputFile));
    std::cout << "ResizeHmfsSingleTest_d_003 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_d_004
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_d_004, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_d_004 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-s");
    params.push_back("-t");
    params.push_back("102400");
    params.push_back("-d");
    params.push_back("-1");
    ASSERT_EQ(1, ResizeHmfsSingleTest::ExecResizeBinary("hmfs", params, device));
    std::cout << "ResizeHmfsSingleTest_d_004 END" << std::endl;
}

/*
 * @tc.name: ResizeHmfsSingleTest_f_001
 * @tc.desc: test for resize hmfs.
 * @tc.type: FUNC
 */
HWTEST_F(ResizeHmfsSingleTest, ResizeHmfsSingleTest_f_001, TestSize.Level1)
{
    std::cout << "ResizeHmfsSingleTest_f_001 BEGIN" << std::endl;
    std::string device = "/data/FsTest";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableDdCmd(device, 100));
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableMkfsCmd("hmfs", device));

    std::vector<std::string> params;
    params.clear();
    params.push_back("-f");
    std::string outputFile = "/data/test_output.txt";
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecResizeBinaryWithOutput("hmfs", params, device, outputFile));
    std::string output = ReadFile(outputFile);
    ASSERT_TRUE(output.find("Info: Done to rebuild checkpoint blocks") != std::string::npos);
    ASSERT_EQ(0, ResizeHmfsSingleTest::ExecutableRmCmd(outputFile));
    std::cout << "ResizeHmfsSingleTest_f_001 END" << std::endl;
}
} // namespace Hmfs
} // namespace OHOS